package com.hbpu.encap.IO;

import java.io.*;
import java.util.Properties;

public class Homework03 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Properties properties = new Properties();
        try {
            properties.load(new FileReader("D:\\HBPUcode\\demo\\demo01\\Chapter02\\src\\dog.properties"));
            int age = Integer.parseInt(properties.getProperty("age"));
            Dog dog = new Dog(properties.getProperty("name"), age, properties.getProperty("color"));
            System.out.println(dog.toString());
        } catch (IOException e) {
            System.out.println("读取失败！" + e.getMessage());
        }

        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\HBPUcode\\demo\\demo01\\Chapter02\\src\\dog.dat"));
        oos.writeObject(new Dog("jack", 18, "blue"));
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\HBPUcode\\demo\\demo01\\Chapter02\\src\\dog.dat"));
        Object o = ois.readObject();
        System.out.println(o);
        ois.close();
    }
}

